<template>
  <view class="selectHotel">
    <BaseNavbar :title="`选择${vPointName}${from == 'home_placeAdd' ? '账号' : ''}`" />
    <BaseSearch :placeholder="'请输入' + vPointName + '名'" @search="search" />
    <view class="hotelItemContent">
      <ComList :loading-type="loadingType">
        <view v-for="(item, index) in listData" :key="index" class="hotelItem">
          <radio :checked="selectIndex == index" color="#2979ff" style="transform: scale(0.7)" />

          <view class="hotelItemDesc" @click="select(item, index)">
            <view class="hotelItemDescContent">

              <view v-if="from == 'home_placeAdd'">
                <view class="hotelName">{{
                  item.user_login ? item.user_login : ""
                }}</view>
              </view>
              <view v-else>
                <view class="hotelName">{{
                  item.hotelName ? item.hotelName : ""
                }}</view>
              </view>
              <view v-if="from == 'home_placeAdd'">
                <view class="hotelName">{{
                  item.roleName ? item.roleName : ""
                }}</view>
              </view>
              <view v-else>
                <view class="address">{{
                  item.address ? item.address : ""
                }}</view>
              </view>

            </view>
            <view class="linkContent">
              <view v-if="from == 'home_placeAdd'">
                <view class="hotelName">分成比例：{{
                  item.per ? `${(item.per * 1).toFixed(0)}%` : "0%"
                }}</view>
              </view>
              <view v-else>
                <view class="linkman">{{
                  item.linkman ? item.linkman : ""
                }}</view>
                <view class="phoneNumber">{{
                  item.linkmanPhone ? item.linkmanPhone : ""
                }}</view>
              </view>

            </view>
          </view>
        </view>
      </ComList>
    </view>
    <!-- <view @click="ok()">
      确认
    </view> -->
  </view>
</template>

<script>
import myPull from "@/mixins/myPull.js";
import BaseSearch from "@/components/base/BaseSearch.vue";
import BaseNavbar from "../../components/base/BaseNavbar.vue";
import ComList from "../../components/list/ComList.vue";

export default {
  data() {
    return {
      code: 0,
      isFoucs: false,
      isConfirm: false,
      from: "",
      hotelName: "",
      selectIndex: -1,
    };
  },
  components: {
    BaseNavbar,
    BaseSearch,
    ComList,
  },
  methods: {
    ok() {
      let data = this.listData.filter((item) => item.checked == true)
      console.log('data选中数据', data)
    },
    async getList(page, done) {

      // 获取数据
      let rtnData
      if (this.from == 'home_placeAdd') {
        let data = {
          select_role_id: 6,
          page: page,

        };
        rtnData = await this.$u.api.getMyUserList(data);
      } else {
        let data = {
          hotel_name: this.hotelName,
          page: page,
          limit: 10,
        };
        rtnData = await this.$u.api.getMyHotels(data);

      }


      done(rtnData.data);
    },
    select(item, index) {
      this.selectIndex = index;
      if (
        (this.from &&
          (this.from === "home_device_bind_hotel" ||
            this.from === "home_order" ||
            this.from === "home_device_or_rep" ||
            this.from === "home_user_infor")) ||
        this.from === "home_pur" || // 来自采购列表
        this.from === "home_device_detail" ||
        this.from == "home_device_bind_place" ||
        this.from == "home_placeAdd"
      ) {
        // 设备商品列表
        // 修改指定位置的数据
        var pages = getCurrentPages();
        console.log("pages", pages);
        var currPage = pages[pages.length - 1]; //当前页面
        var prevPage = pages[pages.length - 2]; //上一个页面
        //直接调用上一个页面的setData()方法，把数据存到上一个页面中去
        prevPage.setData({
          item: item,
        });
        uni.navigateBack({
          delta: 1,
        });

        return;
      }
    },
    search(text) {
      this.hotelName = text;
      this.refresh();
    },
  },
  onLoad(options) {
    if (options.from) {
      this.from = options.from;
    }
    this.refresh();
  },

  mixins: [myPull({})],
};
</script>



<style lang="scss">
page {
  background-color: $pageBgColor;
}
</style>

<style lang="scss" scoped>
$margin-buttom-item: 10rpx;

.hotelItem {
  width: 100%;
  background: rgba(255, 255, 255, 1);
  display: flex;
  align-items: center;
  border-bottom: 1rpx solid rgba(229, 229, 229, 1);
  border-radius: $cardRadius;
  box-sizing: border-box;
  padding: 20rpx 30rpx;
  margin-bottom: 20rpx;

  .hotelItemDesc {
    width: 100%;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;

    .hotelName {
      font-size: $font-size-middle;
      color: rgba(40, 40, 40, 1);
      width: 250rpx;

      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }

    .address {
      width: 250rpx;

      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      color: rgba(104, 104, 104, 1);
    }

    .address,
    .linkman {
      color: rgba(104, 104, 104, 1);
    }

    view:last-child {
      font-size: 16rpx;
    }

    .hotelItemDescContent view {
      &:first-child {
        font-size: $font-size-middle;
        margin-bottom: $margin-buttom-item;
      }

      &:last-child {
        font-size: $font-size-base;
      }
    }

    .linkContent view {
      text-align: right;
      color: rgba(104, 104, 104, 1);

      &:first-child {
        font-size: $font-size-middle;
        margin-bottom: $margin-buttom-item;
      }

      &:last-child {
        font-size: $font-size-base;
      }
    }
  }
}
</style>